import 'package:flutter/material.dart';
import '../allmymoney/allmymoney.dart';

class MyPage extends StatefulWidget {
  @override
  _MyPageState createState() => _MyPageState();
}

class _MyPageState extends State<MyPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: Center(
            child: Text(
          '我的',
          textAlign: TextAlign.center,
          style: TextStyle(fontSize: 18),
        )),
        bottom: PreferredSize(
            preferredSize: const Size.fromHeight(48.0),
            child: ListTile(
                leading: Container(
                  child: Image.asset(
                    'assets/images/pai.jpeg',
                    fit: BoxFit.fill,
                    width: 48,
                  ),
                  decoration: BoxDecoration(
                      border: Border.all(
                          width: 2,
                          color: Colors.blueAccent[100],
                          style: BorderStyle.solid),
                      borderRadius: BorderRadius.circular(4)),
                ),
                title: Text('飘',
                    style: TextStyle(
                        color: Colors.white,
                        fontSize: 20,
                        fontWeight: FontWeight.w500)),
                subtitle: Text(
                  '187****8194',
                  style: TextStyle(color: Colors.white),
                ),
                trailing: Container(
                  child: Icon(
                    Icons.arrow_forward_ios,
                    color: Colors.white,
                    size: 16,
                  ),
                ))),
        actions: <Widget>[
          Center(
            child: Icon(Icons.settings),
          ),
          Container(
            width: 16,
            height: 16,
          )
        ],
      ),
      body: MyPageBody(),
    );
  }
}

class MyPageBody extends StatefulWidget {
  @override
  _MyPageBodyState createState() => _MyPageBodyState();
}

class _MyPageBodyState extends State<MyPageBody> {
  List vipList = [
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '支付宝会员',
      'expan': '铂金会员',
      'right': '16积分即将消失',
      'icon': 0xe611,
      // 'iconColor': Color(0xffe76459)
    },
  ];
  List moneyActions = [
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '账单',
      'expan': '',
      'right': '',
      'icon': 0xe608,
      'iconColor': Color.fromARGB(255, 255, 181, 21)
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '总资产',
      'expan': '',
      'icon': 0xe684,
      'rightColor': Colors.green[400],
      'right': '账户保障免费升级',
      // 'tapFunction':(BuildContext contex){
      //   Navigator.push(context, MaterialPageRoute(builder: (_) {
      //   return  AllmymoneyPage();
      // }));
      // }
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '余额',
      'expan': '',
      'icon': 0xe619,
      'right': '234343.00'
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '余额宝',
      'expan': '',
      'right': '',
      'icon': 0xe61a,
      'iconColor': Color(0xffe76459),
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '花呗',
      'expan': '',
      'right': '',
      'icon': 0xe621,
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '余利宝',
      'expan': '',
      'right': '',
      'icon': 0xe604,
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '银行卡',
      'expan': '',
      'right': '',
      'iconColor': Color.fromARGB(255, 255, 181, 21),
      'icon': 0xe83c,
    },
  ];

  List aliActions = [
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '芝麻信用',
      'expan': '',
      'right': '',
      'icon': 0xe62a,
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '蚂蚁保',
      'expan': '',
      'right': '',
      'icon': 0xe661,
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '相互宝',
      'expan': '',
      'iconColor': Color(0xfee76459),
      'icon': 0xe655,
      'right': '',
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '借呗',
      'icon': 0xe613,
      'expan': '',
      'right': ''
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '网商贷',
      'icon': 0xe61b,
      'expan': '',
      'right': ''
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'icon': 0xe635,
      'title': '网商银行',
      'expan': '',
      'right': ''
    },
  ];
  List common = [
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '我的小程序',
      'icon': 0xe797,
      'expan': '',
      'right': ''
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '我的公益',
      'icon': 0xe75c,
      'expan': '',
      'right': ''
    },
    {
      'img': 'assets/images/swiper1.jpg',
      'title': '我的客服',
      'icon': 0xea0c,
      'expan': '',
      'right': ''
    },
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 855,
      decoration: BoxDecoration(color: Color(0x11111111)),
      child: ListView(
        children: <Widget>[
          mycard(context, vipList),
          mycard(context, moneyActions),
          mycard(context, aliActions),
          mycard(context, common),
          Container(height: 28, child: Text('')),
          Center(
              child: Text('生活好 支付宝',
                  style: TextStyle(
                      fontStyle: FontStyle.italic,
                      fontSize: 16,
                      color: Colors.grey,
                      fontWeight: FontWeight.w500)))
          // 貌似图片更好
        ],
      ),
    );
  }
}

Widget mycard(BuildContext context, List items) {
  List<Widget> arr = items.map((item) {
    return GestureDetector(
      onTap: () {
        print('----tap---');
        Navigator.push(context, MaterialPageRoute(builder: (_) {
          return AllmymoneyPage();
        }));
      },
      child: Row(
        children: <Widget>[
          item['icon'] == null
              ? Image.asset(
                  item['img'],
                  fit: BoxFit.fill,
                  width: 48,
                  height: 48,
                )
              : Container(
                  height: 48,
                  child: Icon(IconData(item['icon'], fontFamily: 'iconFont'),
                      size: 30,
                      color: item['iconColor'] == 'none'
                          ? null
                          : item['iconColor'] ??
                              Theme.of(context).primaryColor),
                  padding: EdgeInsets.only(right: 17),
                ),
          Text(item['title']),
          Expanded(
            child: Text(item['expan'],
                style: TextStyle(color: item['expanColor'])),
          ),
          Text(
            item['right'],
            style: TextStyle(
              color: item['rightColor'] ?? Colors.grey,
            ),
          ),
          Icon(
            Icons.arrow_forward_ios,
            color: Colors.grey,
            size: 12,
          )
        ],
      ),
    );
  }).toList();
  List<Widget> rowlist =
      List.generate(arr.length == 0 ? 0 : arr.length * 2 - 1, (index) {
    //  return index%2==1?Divider(color: Colors.grey,height: 0.5,):arr[index];
    return index % 2 == 1
        ? Divider(
            color: Color.fromRGBO(0, 0, 0, 0.2),
            height: 0.5,
          )
        : arr[(index ~/ 2).toInt()];
  });
  // Divider(color: Colors.grey,height: 0.5,),
  return Container(
    child: Column(children: rowlist),
    height: (48.0 + 0.5) * items.length,
    alignment: Alignment.center,
    decoration: BoxDecoration(
        color: Color(0xFFFFFFFF), borderRadius: BorderRadius.circular(4)),
    margin: const EdgeInsets.only(top: 8, left: 16, right: 16),
    padding: const EdgeInsets.only(left: 16, right: 16),
  );
}
